package cn.cheln.support.mobile.sdcard;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import cn.cheln.explorer.actions.OperationUtil;
import cn.cheln.explorer.ds.database.MimeSrc;
import cn.cheln.explorer.ds.uri.NavigationPool;
import cn.cheln.explorer.ui.ViewHolder;
import cn.cheln.support.log.Logs;
import com.direction.hold.ui.CommonActivity;
import com.direction.hold.ui.CountActivity;
import com.direction.hold.ui.FileCursorActivity;
import com.direction.hold.ui.PathActivity;
import java.io.File;

public class SDcardChecker
{
  public static MediaScannerBroadcast broadcastRec;
  static Context ctx;
  static IntentFilter intentFilter;
  public static boolean isSDAvailable;
  public static boolean mediaScanning;
  public static int mediaUpdating = 0;
  public static View no_file_layout;
  int type = -1;

  public static IntentFilter getSDcardIntentListener()
  {
    if (intentFilter != null)
      return intentFilter;
    intentFilter = new IntentFilter("android.intent.action.MEDIA_SCANNER_STARTED");
    intentFilter.addAction("android.intent.action.MEDIA_MOUNTED");
    intentFilter.addAction("android.intent.action.MEDIA_UNMOUNTED");
    intentFilter.addAction("android.intent.action.MEDIA_REMOVED");
    intentFilter.addAction("android.intent.action.MEDIA_SHARED");
    intentFilter.addAction("android.intent.action.MEDIA_BAD_REMOVAL");
    intentFilter.addAction("android.intent.action.MEDIA_SCANNER_FINISHED");
    intentFilter.addDataScheme("file");
    return intentFilter;
  }

  public static boolean isSDCardAvailable()
  {
    isSDAvailable = Environment.getExternalStorageState().equals("mounted");
    return isSDAvailable;
  }

  public static void registerSDcardIntentListener(Context paramContext, BroadcastReceiver paramBroadcastReceiver)
  {
    paramContext.registerReceiver(paramBroadcastReceiver, getSDcardIntentListener());
    ctx = paramContext;
  }

  public static void setCommonActivity(CommonActivity paramCommonActivity)
  {
    if (broadcastRec == null)
      return;
    broadcastRec.setCommonActivity(paramCommonActivity);
  }

  public static boolean srcardStateResolve()
  {
    return (!(isSDCardAvailable()));
  }

  public static boolean srcardStateResolve(boolean paramBoolean, Activity paramActivity)
  {
    if (!(isSDCardAvailable()))
    {
      if (paramBoolean)
      {
        no_file_layout = LayoutInflater.from(paramActivity).inflate(2130903057, null);
        ((TextView)no_file_layout.findViewById(2131230848)).setText(2131034178);
        no_file_layout.setVisibility(0);
        paramActivity.setTheme(16973829);
        paramActivity.setContentView(no_file_layout);
      }
      return true;
    }
    no_file_layout = null;
    return false;
  }

  public static void unregisterSDcardIntentListener(Context paramContext, BroadcastReceiver paramBroadcastReceiver)
  {
    ctx.unregisterReceiver(paramBroadcastReceiver);
  }

  public static final class MediaScannerBroadcast extends BroadcastReceiver
  {
    public static String scanCat;
    CommonActivity activity;
    File imagepath;
    boolean restart;
    Intent switchIntent;

    public void onReceive(Context paramContext, Intent paramIntent)
    {
      Logs.i("test", "intent.getAction() -- " + paramIntent.getAction());
      if (paramIntent.getAction().equals("android.intent.action.MEDIA_SCANNER_FINISHED"))
      {
        Logs.i("------------------ receive message 111");
        CountActivity.categoryActivity.setScanBarHide(true);
        MimeSrc.recountCategoryNum(paramContext);
        if (CountActivity.categoryActivity != null)
        {
          if (!(CountActivity.categoryActivity.navTool.isAtTop()))
            break label146;
          CountActivity.categoryActivity.getViewHolderInstance().dataChanged(new Object[0]);
          CountActivity.categoryActivity.getViewHolderInstance().rebind();
        }
        if (SDcardChecker.mediaScanning)
        {
          if (scanCat != null)
            label92: Toast.makeText(paramContext, paramContext.getString(2131034229) + scanCat, 0).show();
          SDcardChecker.mediaScanning = false;
          scanCat = null;
        }
      }
      do
      {
        return;
        label146: CountActivity.categoryActivity.refresh();
        break label92:
        SDcardChecker.mediaUpdating = -1 + SDcardChecker.mediaUpdating;
        if ((SDcardChecker.mediaUpdating == 0) && (OperationUtil.operationRunnableOver))
        {
          Message localMessage = new Message();
          localMessage.what = 0;
          localMessage.obj = OperationUtil.operatingDialog;
          this.activity.handler.sendMessage(localMessage);
        }
        while (true)
        {
          if (CountActivity.categoryActivity != null);
          CountActivity.categoryActivity.getViewHolderInstance().refresh();
          return;
          if (SDcardChecker.mediaUpdating >= 0)
            continue;
          SDcardChecker.mediaUpdating = 0;
        }
        if ((!(paramIntent.getAction().equals("android.intent.action.MEDIA_UNMOUNTED"))) && (!(paramIntent.getAction().equals("android.intent.action.MEDIA_REMOVED"))) && (!(paramIntent.getAction().equals("android.intent.action.MEDIA_BAD_REMOVAL"))) && (!(paramIntent.getAction().equals("android.intent.action.MEDIA_SHARED"))) && (!(paramIntent.getAction().equals("android.intent.action.MEDIA_SCANNER_SCAN_FILE"))))
          continue;
        SDcardChecker.srcardStateResolve(true, CountActivity.categoryActivity);
        SDcardChecker.srcardStateResolve(true, PathActivity.activityInstance);
        return;
      }
      while (!(paramIntent.getAction().equals("android.intent.action.MEDIA_MOUNTED")));
      CountActivity.categoryActivity.finished = true;
      CountActivity.categoryActivity.recovery();
      PathActivity.codePerformed = false;
      PathActivity.activityInstance.recovery();
    }

    public void setCommonActivity(CommonActivity paramCommonActivity)
    {
      this.activity = paramCommonActivity;
    }
  }
}

/* Location:           H:\360云盘\lewa_explorer_3.0\bin\FileApp_orig_dex2jar.jar
 * Qualified Name:     cn.cheln.support.mobile.sdcard.SDcardChecker
 * JD-Core Version:    0.5.2
 */